package isp.apps.example.shoppingcart.persistence.hibernate;

import isp.apps.example.shoppingcart.domain.OrderStatus;
import isp.apps.example.shoppingcart.persistence.OrderStatusRepository;
import isp.apps.example.shoppingcart.persistence.PersistenceManagerFactory;

import isp.utils.cjis.persistence.PersistenceException;
import isp.utils.cjis.persistence.PersistenceManager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HibernateOrderStatusRepository
  implements OrderStatusRepository
{
  private PersistenceManager persistenceManager =
    PersistenceManagerFactory.getPersistenceManager();

  private static final Log log =
    LogFactory.getLog(HibernateCartItemsRepository.class);

  public HibernateOrderStatusRepository()
  {
  }

  public void saveOrderStatus(OrderStatus os)
  {
    try
    {
      if (os.getId() == null)
        persistenceManager.save(os);
      else
        persistenceManager.update(os);
    }
    catch (PersistenceException pe)
    {
      log.error(pe, pe);
    }
  }

  public void deleteOrderStatus(OrderStatus os)
  {
    try
    {
      persistenceManager.delete(os);
    }
    catch (PersistenceException pe)
    {
      log.error(pe, pe);
    }
  }
}
